<template>
  <div class="train">
    <Loading :isLoading = "isLoading" />
    <p class="train-explain">Whether you are winning over a prospect or supporting an existing customer, victory goes to the best prepared. That is why we have set up two training and certification programs: the Peplink Certified Engineer (PCE), and Peplink Certified Sales Specialist (PCSS). These two programs will equip your team with the knowledge and skills they need to overcome any challenge.</p>
    <div class="train-list" @click="goToDetails">
      <div class="item" v-for="(item,index) in trainArr" :key="item.id">
        <img :src="item.image_main" alt="" @error="getError">
        <div class="content">
          <h4 :title="item.title">{{item.title}}</h4>
          <p>{{item.intro}}</p>
          <LearnButton :title="item.id+''"/>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {ref, onMounted} from 'vue'
import {useRouter} from 'vue-router'
import LearnButton from '../LearnButton.vue'
import {getTrainList} from "../../api/support";
import Loading from '../Loading.vue'
import logoImg from "../../assets/logo-error-small.png"
export default {
  name: "Train",
  components:{LearnButton,Loading},
  setup(){
    const router = useRouter()
    const trainArr = ref([])
    let isLoading = ref(true)
    onMounted(()=>{
      getTrainList().then((res)=> {
        if(res && res.code === 200){
          trainArr.value = res.data
          isLoading.value = false
        }
      })
    })
    const getError = (e) => {
      e.target.src = logoImg
    }
    const goToDetails = (el)=>{
      if(el.target.title){
        router.push({path:'/support/trainDetail',query:{id:el.target.title*1}});
      }
    }
    return{
      trainArr,
      getError,
      goToDetails,
      isLoading
    }
  }
}
</script>

<style scoped lang="scss">
.train{
  .train-explain{
    margin: 30px 0;
    font-size:18px;
    line-height: 30px;
    padding-right:300px;
  }
  .train-list{
    display:grid;
    grid-template-columns: repeat(2, 1fr);
    grid-gap: 20px;
    margin-bottom:30px;
    .item{
      position: relative;
      img{
        width:100%;
        height:500px;
        object-fit: cover;
      }
      .content{
        position: absolute;
        top:50%;
        transform:translateY(-50%);
        text-align: left;
        padding-left: 20px;
        color:white;
        h4{
          font-size:30px;
          font-weight:600;
          line-height: 60px;
          color:white;
          margin-bottom: 0;
          word-break:break-all;
        }
        p{
          font-size:16px;
          line-height: 30px;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
      }
    }
  }
}
</style>
